home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Games / Starter / JST / Developer / sources / OSEmu / lowlevel.s < prev    next >
Encoding:
Text File  |  1999-12-03  |  8.7 KB  |  424 lines

  1. * $Id: lowlevel.s 1.1 1999/02/03 04:08:28 jotd Exp $
  2.  
  3. TEST_JOY_BUTTON:MACRO
  4.     bclr    #JPB_BUTTON_\1,D0    ; button released
  5.     tst.l    D2
  6.     bne.b    .rts\@
  7.     bset    #JPB_BUTTON_\1,D0    ; button pressed
  8. .rts\@
  9.     ENDM
  10.  
  11. **************************************************************************
  12. *   LOWLEVEL-LIBRARY                                                    *
  13. **************************************************************************
  14. **************************************************************************
  15. *   INITIALIZATION                                                       *
  16. **************************************************************************
  17.  
  18. LOWLINIT    move.l    _lowlbase,d0
  19.         beq    .init
  20.         rts
  21.  
  22. .init        move.l    #162,d0        ; reserved function
  23.         move.l    #80,d1        ; 20 variables: should be OK
  24.         lea    _lowlname,a0
  25.         bsr    _InitLibrary
  26.         move.l    d0,a0
  27.         move.l    d0,_lowlbase
  28.         
  29.         patch    _LVOReadJoyPort(a0),READJOYPORT(pc)
  30.         patch    _LVOSetJoyPortAttrsA(a0),SETJOYPORTATTRS(pc)
  31.         patch    _LVOAddVBlankInt(a0),ADDVBLANKINT(pc)
  32.         patch    _LVOAddKBInt(a0),ADDKBINT(pc)
  33.         patch    _LVOAddTimerInt(a0),ADDTIMERINT(pc)
  34.         patch    _LVORemVBlankInt(a0),MYRTS(pc)
  35.         patch    _LVORemKBInt(a0),MYRTS(pc)
  36.         patch    _LVOSystemControlA(a0),MYRTZ(pc)
  37.         patch    _LVOGetLanguageSelection(a0),GETLANGSEL(pc)
  38.         rts
  39.  
  40. GETLANGSEL:
  41.     moveq.l    #2,D0    ; british english
  42.     rts
  43.  
  44. ; adds a vblank interrupt
  45. ; < A0: intRoutine
  46. ; < A1: intData
  47.  
  48. ADDVBLANKINT:
  49.     movem.l    D2-D7/A2-A6,-(A7)
  50.     lea    .int_entry(pc),A3
  51.     move.l    A0,(A3)
  52.     lea    .caller_int(pc),A0
  53.  
  54.     lea    .int_struct(pc),A3
  55.     move.b    #NT_INTERRUPT,8(A3)    ; ln_Type = INTERRUPT
  56.     move.b    #0,9(A3)        ; Highest priority
  57.     move.l    .vbname,10(A3)        ; The name of the server (for monitor programs)
  58.     move.l    A0,18(A3)        ; The new interrupt server code to chain with
  59.     move.l    A1,14(A3)        ; The data to pass in A1 at each call
  60.     move.l    #INTB_VERTB,D0        ; Vertical Blank interrupt
  61.     move.l    $4.W,A6
  62.     move.l    A3,A1            ; pointer on interrupt structure
  63.     JSR    _LVOAddIntServer(A6)    ; Adds the handler to the existing chain
  64.     
  65.     movem.l    (A7)+,D2-D7/A2-A6
  66.  
  67.     moveq.l    #1,D0            ; returns !=0 because success
  68.     rts
  69.  
  70. .caller_int:
  71.     move.l    .int_entry(pc),A5    ; as required in lowlevel autodoc
  72.     jmp    (A5)
  73.  
  74. .int_entry:
  75.     dc.l    0
  76. .int_struct:
  77.     ds.b    22
  78. .vbname:    
  79.     dc.b    "lowlevel vbl",0
  80.     cnop    0,4
  81.  
  82. ; adds a keyboard interrupt
  83. ; < A0: intRoutine
  84. ; < A1: intData
  85.  
  86. ADDKBINT:
  87.     movem.l    D2-D7/A2-A6,-(A7)
  88.     lea    .int_entry(pc),A3
  89.     move.l    A0,(A3)
  90.     lea    .caller_int(pc),A0
  91.  
  92.     lea    .int_struct(pc),A3
  93.     move.b    #NT_INTERRUPT,8(A3)    ; ln_Type = INTERRUPT
  94.     move.b    #0,9(A3)        ; Highest priority
  95.     move.l    .vbname,10(A3)        ; The name of the server (for monitor programs)
  96.     move.l    A0,18(A3)        ; The new interrupt server code to chain with
  97.     move.l    A1,14(A3)        ; The data to pass in A1 at each call
  98.     move.l    #INTB_PORTS,D0        ; Ports interrupt
  99.     move.l    $4.W,A6
  100.     move.l    A3,A1            ; pointer on interrupt structure
  101.     JSR    _LVOAddIntServer(A6)    ; Adds the handler to the existing chain
  102.     
  103.     movem.l    (A7)+,D2-D7/A2-A6
  104.     moveq.l    #1,D0            ; returns !=0 because success
  105.     rts
  106.  
  107. .caller_int:
  108.     move.l    .int_entry(pc),A5    ; as required in lowlevel autodoc
  109.     move.b    $BFEC01,D0
  110.     not.b    D0
  111.     ror.b    #1,D0            ; raw keycode
  112.     jmp    (A5)
  113.  
  114. .int_entry:
  115.     dc.l    0
  116. .int_struct:
  117.     ds.b    22
  118. .vbname:    
  119.     dc.b    "lowlevel kb",0
  120.     cnop    0,4
  121.  
  122. ; adds a timer interrupt
  123. ; < A0: intRoutine
  124. ; < A1: intData
  125.  
  126. CIA_TIME_SLICE = 46911
  127.  
  128. ADDTIMERINT:
  129.     movem.l    D2-D7/A2-A6,-(A7)
  130.  
  131.     ; just stores the values
  132.  
  133.     move.l    A0,cia_int_entry
  134.     move.l    A1,cia_int_data
  135.  
  136.     move.l    $4.W,A6
  137.     lea    _ciaaname,A1
  138.     JSR    _LVOOpenResource
  139.     move.l    D0,cia_resource_handler        ; resource handler
  140.  
  141.     lea    cia_caller_int(pc),A0
  142.  
  143.     lea    cia_int_struct(pc),A3
  144.     move.b    #NT_INTERRUPT,8(A3)    ; ln_Type = INTERRUPT
  145.     move.b    #127,9(A3)        ; Lowest priority
  146.     move.l    cia_int_name,10(A3)        ; The name of the server (for monitor programs)
  147.     move.l    A0,18(A3)        ; The new interrupt server code to chain with
  148.     move.l    A1,14(A3)        ; The data to pass in A1 at each call
  149.     move.l    #3,D0        
  150.  
  151.     move.l    cia_int_struct(pc),D0    ; only 1 interrupt of this kind
  152.     movem.l    (A7)+,D2-D7/A2-A6
  153.     rts
  154.  
  155. ; A1 <: intHandle (also interrupt structure, hack!)
  156. ; D0 <: time interval (in microseconds)
  157. ; D1 <: continuous (0: one shot)
  158.  
  159. STARTTIMERINT:
  160.     movem.l    D2-D7/A2-A6,-(A7)
  161.  
  162.     move.l    d0,cia_time_interval
  163.  
  164.     move.l    cia_resource_handler,A6
  165.     move.l    #3,D0    
  166.     JSR    _LVOAddICRVector(A6)    ; Adds the handler to the existing chain
  167.     
  168.     movem.l    (A7)+,D2-D7/A2-A6
  169.     rts
  170.  
  171. ; <A1: intHandle
  172.  
  173. STOPTIMERINT:
  174.     movem.l    D2-D7/A2-A6,-(A7)
  175.  
  176.     moveq.l    #3,D0
  177.     move.l    cia_resource_handler,A6
  178.     JSR    _LVORemICRVector(A6)    ; Removes the handler to the existing chain
  179.     
  180.     movem.l    (A7)+,D2-D7/A2-A6
  181.     rts
  182.  
  183. ; routine called by ICRVector
  184.  
  185. cia_caller_int:
  186.     ; time counter, to avoid calling user routine every time
  187.     ; we must check the frequence he requested
  188.  
  189.     ;;to be continued
  190.     ;
  191.  
  192.     move.l    cia_int_entry(pc),A5    ; as required in lowlevel autodoc
  193.     move.l    cia_int_data(pc),A1    ; as required in lowlevel autodoc
  194.     jmp    (A5)
  195.  
  196. cia_resource_handler:
  197.     dc.l    0
  198. cia_time_interval:
  199.     dc.l    0
  200.  
  201. cia_int_struct:
  202.     ds.b    22
  203. cia_int_name:    
  204.     dc.b    "lowlevel timer",0
  205.     cnop    0,4
  206. cia_int_entry:
  207.     dc.l    0
  208. cia_int_data:
  209.     dc.l    0
  210.  
  211.  
  212. ; forces a port to a controller type and allows to reset it
  213.  
  214. SETJOYPORTATTRS:
  215.     moveq.l    #-1,D0    ; all went OK
  216.     rts
  217.  
  218. ; reads joypads
  219.  
  220. READJOYPORT:
  221.     cmp.w    #0,D0
  222.     beq    .joy0
  223.     cmp.w    #1,D0
  224.     beq    .joy1
  225.  
  226.     move.l    #JP_TYPE_NOTAVAIL,D0
  227.     rts
  228. .joy0
  229.     move.l    #JP_TYPE_GAMECTLR,D0    ; joypad connected
  230.  
  231.     btst    #6,$bfe001
  232.     bne    .nob1_0
  233.  
  234.     bset    #JPB_BUTTON_RED,D0    ; fire/lmb
  235.     
  236. .nob1_0:
  237.  
  238.     btst    #6,potinp+$DFF000
  239.     bne    .nob2_0
  240.  
  241.     bset    #JPB_BUTTON_BLUE,D0    ; fire 2/rmb
  242.     move.w    #$CC01,potgo+$DFF000    ; reset ports
  243. .nob2_0    
  244.     ; joystick moves
  245.  
  246.     lea    (joy0dat+_custom),A6
  247.     bsr    .joy_test
  248.  
  249.     rts
  250.  
  251. .joy1
  252.     move.l    #JP_TYPE_GAMECTLR,D0    ; joypad connected
  253.  
  254.     btst    #7,$bfe001
  255.     bne    .nob1_1
  256.  
  257.     bset    #JPB_BUTTON_RED,D0    ; fire/lmb
  258.     
  259. .nob1_1:
  260.  
  261. ;    btst    #14,potinp+$DFF000    ; was wrong ?
  262.     btst    #6,potinp+$DFF000
  263.     bne    .nob2_1
  264.  
  265.     bset    #JPB_BUTTON_BLUE,D0    ; fire 2/rmb
  266.     move.w    #$CC01,(potgo+_custom)    ; reset ports
  267. .nob2_1:
  268.  
  269.     ; joystick moves
  270.  
  271.     lea    (joy1dat+_custom),A6
  272.     bsr    .joy_test
  273.     move.l    D0,-(A7)
  274.     movem.l    D1/D2,-(A7)
  275.     move.l    old_buttonmask,D0
  276.     bsr    .button_test
  277.     movem.l    (A7)+,D1/D2
  278.     move.l    D0,old_buttonmask
  279.     or.l    (A7),D0
  280.     move.l    D0,(A7)
  281.     move.l    (A7)+,D0
  282.     rts
  283.  
  284. ; other joypad buttons by keyboard emulation
  285. ; even a real joypad does not work properly on a real amiga!
  286. ; (I don't really know why!)
  287.  
  288.  
  289. .button_test:
  290.     move.b    KBDVAL,D1
  291.  
  292.     ; press/release
  293.  
  294.     moveq.l    #0,D2
  295.     bclr    #7,D1
  296.     beq.b    .pressed
  297.     moveq.l    #1,D2
  298. .pressed
  299.  
  300.     cmp.b    #$50,D1        ; F1: Blue
  301.     bne    .noblue
  302.     TEST_JOY_BUTTON    BLUE    ; fire 2/blue/rmb
  303.     rts
  304. .noblue
  305.     cmp.b    #$51,D1        ; F2: Green
  306.     bne    .nogreen
  307.     TEST_JOY_BUTTON    GREEN
  308.     rts
  309. .nogreen:
  310.     cmp.b    #$52,D1        ; F3: Yellow
  311.     bne    .noyellow
  312.     TEST_JOY_BUTTON    YELLOW
  313.     rts
  314. .noyellow:
  315.     cmp.b    #$53,D1        ; F4: Play/pause
  316.     bne    .noplay
  317.     TEST_JOY_BUTTON    PLAY
  318.     rts
  319. .noplay:
  320.     cmp.b    #$54,D1        ; F5: left ear
  321.     bne    .nolear
  322.     TEST_JOY_BUTTON    REVERSE
  323.     rts
  324. .nolear:
  325.     cmp.b    #$55,D1        ; F6: right ear
  326.     bne    .norear
  327.     TEST_JOY_BUTTON    FORWARD
  328. .norear:
  329.     rts
  330.  
  331. ; tests joystick moves
  332. ; < A6: custom reg. of the selected joystick
  333. ; > D0: joystick bits set
  334.  
  335. .joy_test:
  336.     movem.l    D4-D6,-(A7)
  337.  
  338.     move.w    (A6),D4
  339.     move.w    D4,D5
  340.     btst    #1,D4
  341.     beq.b    .left_off
  342.     bset    #JPB_JOY_RIGHT,D0
  343.     bra.b    .vert_test
  344. .left_off:
  345.     btst    #9,D4
  346.     beq.b    .vert_test
  347.     bset    #JPB_JOY_LEFT,D0
  348. .vert_test
  349.     lsr.w    #1,D4
  350.     eor.w    D5,D4
  351.     btst    #0,D4
  352.     beq.b    .back_off
  353.     bset    #JPB_JOY_DOWN,D0
  354.     bra.b    .exit
  355. .back_off
  356.     btst    #8,D4
  357.     beq.b    .exit
  358.     bset    #JPB_JOY_UP,D0
  359. .exit
  360.  
  361.     movem.l    (A7)+,D4-D6
  362.     rts
  363.  
  364. old_buttonmask:
  365.     dc.l    0
  366.  
  367.  
  368. LAB_00D7:
  369.     MOVEM.L    D2/A4-A6,-(A7)        ;16A8: 48E7200E
  370.     MOVEA.L    A1,A4            ;16AC: 2849
  371.     MOVEQ    #0,D2            ;16AE: 7400
  372.     MOVE.B    $BFEC01,D2        ;16B0: 143900BFEC01
  373.     NOT.B    D2            ;16B6: 4602
  374.     ROR.B    #1,D2            ;16B8: E21A
  375.     MOVEA.L    (72,A4),A0        ;16BA: 206C0048
  376.     MOVEA.L    (14,A0),A1        ;16BE: 2268000E
  377.     MOVEA.L    (18,A0),A5        ;16C2: 2A680012
  378.     JSR    (A5)            ;16C6: 4E95
  379.     CMP    #$0078,D2        ;16C8: B47C0078
  380.     BEQ.S    LAB_00DD        ;16CC: 6760
  381.     MOVE    D2,D1            ;16CE: 3202
  382.     AND    #$0078,D1        ;16D0: C27C0078
  383.     CMP    #$0060,D1        ;16D4: B27C0060
  384.     BNE.S    LAB_00D8        ;16D8: 6612
  385.     MOVE    (40,A4),D0        ;16DA: 302C0028
  386.     MOVE    D2,D1            ;16DE: 3202
  387.     AND    #$0007,D1        ;16E0: C27C0007
  388.     BCHG    D1,D0            ;16E4: 0340
  389.     MOVE    D0,(40,A4)        ;16E6: 39400028
  390.     BRA.S    LAB_00DA        ;16EA: 601E
  391. LAB_00D8:
  392.     BTST    #7,D2            ;16EC: 08020007
  393.     BNE.S    LAB_00D9        ;16F0: 6606
  394.     MOVE    D2,(42,A4)        ;16F2: 3942002A
  395.     BRA.S    LAB_00DA        ;16F6: 6012
  396. LAB_00D9:
  397.     MOVE    D2,D1            ;16F8: 3202
  398.     BCLR    #7,D1            ;16FA: 08810007
  399.     CMP    (42,A4),D1        ;16FE: B26C002A
  400.     BNE.S    LAB_00DA        ;1702: 6606
  401.     ORI    #$00FF,(42,A4)        ;1704: 006C00FF002A
  402. LAB_00DA:
  403.     MOVE    D2,D0            ;170A: 3002
  404.     SUBI    #$00F9,D2        ;170C: 044200F9
  405.     BPL.S    LAB_00DD        ;1710: 6A1C
  406.     MOVEA.L    (252,A4),A1        ;1712: 226C00FC
  407.     BRA.S    LAB_00DC        ;1716: 600E
  408. LAB_00DB:
  409.     MOVEA.L    (18,A1),A5        ;1718: 2A690012
  410.     MOVEA.L    (14,A1),A1        ;171C: 2269000E
  411.     JSR    (A5)            ;1720: 4E95
  412.     MOVEA.L    (A7)+,A1        ;1722: 225F
  413.     MOVE    (A7)+,D0        ;1724: 301F
  414. LAB_00DC:
  415.     MOVE    D0,-(A7)        ;1726: 3F00
  416.     MOVE.L    (A1),-(A7)        ;1728: 2F11
  417.     BNE.S    LAB_00DB        ;172A: 66EC
  418.     ADDQ    #6,A7            ;172C: 5C4F
  419. LAB_00DD:
  420.     MOVEM.L    (A7)+,D2/A4-A6        ;172E: 4CDF7004
  421.     RTS                ;1732: 4E75
  422.     MOVE.L    (40,A6),D0        ;1734: 202E0028
  423.     RTS                ;1738: 4E75
  424.